#!/usr/bin/env python

class Encoder:
    def __init__(self, text, method):
        self.text = text
        self.method = method
        
    def encode(self, string):
        return self.method(string)

class XSSRule:
    def __init__(self, title, url):
        self.title = title
        self.url = url
        self.contexts = []
        self.encoders = {}
        
    def add_encoder(self, key, encoder):
        self.encoders[key] = encoder
    
    def add_context(self, context):
        self.contexts.append(context)
    
class XSSContext:
    def __init__(self, comment):
        self.context_code = None
        self.comment = comment
        self.vulnerable_form = ''
        self.input = ''
        self.encoded_input = ''
        self.attacks = []
        
    def add_attack(self, attack):
        self.attacks.append(attack)
        
#    def get_filled_form(self):
#        return self.get_form_part(0) + self.input + self.get_form_part(1)
        
    def get_filled_encoded_form(self):
        return self.get_form_part(0) + self.encoded_input + self.get_form_part(1)
        
    def get_form_part(self, part):
        return self.vulnerable_form.split("??")[part]
    
class XSSAttack:
    def __init__(self, comment):
        self.comment = comment
        self.examples = []
        
    def add_example(self, example):
        self.examples.append(example)
    
